home *** CD-ROM | disk | FTP | other *** search
- Path: news.biddeford.com!usenet
- From: Tim Steiger <tsteiger@biddeford.com>
- Newsgroups: comp.lang.c
- Subject: Re: Kind of an annoying question...
- Date: Sat, 16 Mar 1996 13:56:55 -0800
- Organization: Biddeford Internet Corp.
- Message-ID: <314B3927.271A@biddeford.com>
- References: <4hvrio$c4k@lastactionhero.rs.itd.umich.edu>
- NNTP-Posting-Host: bidd23.biddeford.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- Steve Palmer Peng wrote:
- >
- > I'm wondering, just what function in C allows me to enter a character
- > from the keyboard, and it automatically executes the command I designate
- > that character to. For instance, I have something like,
- >
- > printf("Enter Y or N:");
- >
- > and I want the command after the printf statement to wait for input
- > from the keyboard, but once someone enters a Y or an N, the next line of
- > code is executed, without hitting enter. Does anyone know how? It would
- > be greatly appreciated if someone could help me out here...
- >
- > SteveHow about?
-
- #include(conio.h)
- main()
- {
- printf("Enter Y or N: ");
- switch(getch())
- {
- case 'n':
- case 'N': printf("Pressed N!\n");
- break;
- case 'y':
- case 'Y': printf("Pressed Y!\n");
- break;
- default: printf("Didn't press N or Y\n");
- }
- }
-
- ps: If you are in a Unix environment read up on the curses library.
- % man curses
-